import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


public class SimplifiedPoolDriver {
	public static void main(String[] args) {

		// Form the original team list at the start of the season

		List<HockeyPlayer> canucks = new ArrayList<HockeyPlayer>();
		String teamName = "Canucks";

		canucks.add(new HockeyPlayer("Daniel", "Sedin"));
		canucks.add(new HockeyPlayer("Alex", "Burrows"));
		canucks.add(new HockeyPlayer("Henrik", "Sedin"));

		// When someone scores, update their values on the list

		HockeyPlayer looksLikeHenrik = new HockeyPlayer("Henrik", "Sedin");
		int henrikPosition = canucks.indexOf(looksLikeHenrik);
		HockeyPlayer henrikFromList = canucks.get(henrikPosition);
		henrikFromList.addGoal();
		henrikFromList.addGoal();

		HockeyPlayer looksLikeDaniel = new HockeyPlayer("Daniel", "Sedin");
		int danielPosition = canucks.indexOf(looksLikeDaniel);
		HockeyPlayer danielFromList = canucks.get(danielPosition);
		danielFromList.addGoal();

		// produce statistics at the end of the season

		Collections.sort(canucks);
		Collections.reverse(canucks);

		System.out.println();
		System.out.println(teamName + " Scoring Leaders");
		System.out.println();

		for (HockeyPlayer aPlayer : canucks) {
			System.out.println(aPlayer.getLastName() + " "
					+ aPlayer.getFirstName() + " " + aPlayer.getTotalPoints());
		}

		TeamManager myTeam = new TeamManager("Red Wings");

		myTeam.addPlayer(new HockeyPlayer("Joe", "Sakic"));
		myTeam.addPlayer(new HockeyPlayer("Fred", "Flintstone"));
		myTeam.addPlayer(new HockeyPlayer("Sam", "Spade"));

		int numberOfPlayersOnTeam = myTeam.size();

		myTeam.addGoal(new HockeyPlayer("Fred", "Flintstone"));
		myTeam.addGoal(new HockeyPlayer("Fred", "Flintstone"));

		int goalsScored = myTeam.getTotalGoalsScored();

		System.out.println(goalsScored);
		
		// If the team manager supplies positional notation
		// we can use that to retrieve players off the list

		for (int i = 0; i < myTeam.size(); i++) {
			HockeyPlayer somePlayer = myTeam.get(i);
			System.out.println(somePlayer.getFirstName());
		}
		
		// If the team manager supplies an iterator then
		// we can use the iterator pattern
		
		Iterator<HockeyPlayer> fetch = myTeam.iterator();
		while(fetch.hasNext()) {
			HockeyPlayer aPlayer = fetch.next();
			System.out.println(aPlayer.getFirstName());
		}
		
		// But if we have an iterator, a for each loop is the
		// easier way to go through all of them
		// (Note that TeamManager must announce that there iterator
		// above is available but using "implements Iterable"
		
		for(HockeyPlayer aPlayer : myTeam) {
			System.out.println(aPlayer.getFirstName());			
		}	
	}
}
